import React from "react";
import { NavLink, useRoutes, useInRouterContext } from "react-router-dom";

import routes from "./routes";

import Header from "./components/Header";

import "./App.css";

export default function App() {
    // 生成路由表
    const element = useRoutes(routes);

    // 检查本组件是否在路由的上下文中
    console.log(useInRouterContext());

    return (
        <div>
            <div className="row">
                <div className="col-xs-offset-2 col-xs-8">
                    <Header />
                </div>
            </div>
            <div className="row">
                <div className="col-xs-2 col-xs-offset-2">
                    <div className="list-group">
                        <NavLink className="list-group-item" to="/about">
                            About
                        </NavLink>
                        {/* end属性指定当子路由匹配时，父级路由是否还需要高亮 */}
                        <NavLink
                            className="list-group-item"
                            to="/home"
                            end={true}
                        >
                            Home
                        </NavLink>
                    </div>
                </div>
                <div className="col-xs-6">
                    <div className="panel">
                        <div className="panel-body">
                            {/* <Routes>
                                <Route path="/home" element={<Home />} />
                                <Route path="/about" element={<About />} /> */}
                            {/* 重定向使用Route+Naivgate */}
                            {/* <Route
                                    path="/"
                                    element={<Navigate to="/home" />}
                                /> */}
                            {/* </Routes> */}
                            {element}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    );
}
